<template>
    <div class="">
        <div class="system-user-search mb15">
				<el-input size="default" placeholder="请输入患者名称或id" v-model="nameandid" style="max-width: 180px"> </el-input>
				<el-button size="default" type="primary" @click="list()" class="ml10">
					<el-icon>
						<ele-Search />
					</el-icon>
					查询
				</el-button>
				<el-button size="default" type="success" @click="onOpenAddPati()" class="ml10">
					<el-icon>
						<ele-FolderAdd />
					</el-icon>
					新增患者
				</el-button>
			</div>
      <el-table
    :data="pagination.records"
    border 
    style="width: 100%">
    <el-table-column  fixed prop="patients.ptCard"  label="病人编号"   width="150"></el-table-column>
    <el-table-column fixed prop="patients.ptName" label="病人姓名"    width="120"> </el-table-column>
    <el-table-column fixed  prop="daId"  label="医嘱编号"   width="150"></el-table-column>
     <el-table-column  prop="drug.dname"  label="药品名称"   width="300">  </el-table-column>
     <el-table-column prop="sysUser.userName" label="开药医师" width="220"> </el-table-column>
    <el-table-column  prop="daItem" label="医嘱条陈"    width="420"> </el-table-column>
    <el-table-column  prop="daCreateTime"  label="就诊时间"   width="300">  </el-table-column>
    <el-table-column fixed="right"  label="操作" width="100">
      <template slot-scope="scope">
     <el-button @click="del(scope.row)"  type="text" size="small">删除</el-button>
    <el-button type="text" size="small" @click="upPatiUI(scope.row)">编辑</el-button>
      </template>
    </el-table-column>
  </el-table>
  <div class="block">
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :hide-on-single-page="true"
      :current-page="pagination.current"
		  :page-sizes="[3,5,8,10]"
		  :page-size="pagination.size"
		  layout="total,sizes, prev, pager, next, jumper"
		  :total="pagination.total">
    </el-pagination>
  </div>

  <el-dialog title="添加医嘱" :visible.sync="addTag" :close-on-click-modal="false">
			  <el-form :model="addDoctForm" size="small" label-width="90px">
				<el-row :gutter="35">

                <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12"  >
					<el-form-item label="选择患者">
						<el-select v-model="addDoctForm.ptId" placeholder="请选择" style="width:100%">
                            <el-option
                            v-for="item in patientsData"
                            :key="item.ptId"
                            :label="item.ptName"
                            :value="item.ptId">
                            </el-option>
                        </el-select>
						</el-form-item>
		      </el-col>

            <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12"  >
						<el-form-item label="药品">
							<el-select v-model="addDoctForm.daiid" placeholder="请选择"  style="width:100%"  >
                                <el-option
                                v-for="item in drugData"
                                :key="item.did"
                                :label="item.dname"
                                :value="item.did">
                                </el-option>
                            </el-select>
						</el-form-item>
					</el-col>



            <!-- <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12"  >
						<el-form-item label="药品">
							  <el-select
                                v-model="drugvalue"
                                multiple
                                filterable
                                collapse-tags
                                style="margin-left: 20px;"
                                placeholder="请选择">
                                <el-option
                                v-for="item in drugData"
                                :key="item.did"
                                :label="item.dname"
                                :value="item.did">
                                </el-option>
                            </el-select>
						</el-form-item>
					</el-col> -->



                     <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12"  >
						<el-form-item label="药品数量">
							<el-input v-model="addDoctForm.dnum" placeholder="请输入药品数量" clearable></el-input>
						</el-form-item>
					</el-col>


           <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24"  >
						<el-form-item label="医嘱条陈">
							<el-input v-model="addDoctForm.daItem" type="textarea" placeholder="请输入医嘱条陈" clearable></el-input>
						</el-form-item>
					</el-col>

	            <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12"  >
						<el-form-item label="付费状态">
							<el-switch v-model="addDoctForm.dstatus" active-value="y" inactive-value="n" inline-prompt active-text="是" inactive-text="否"></el-switch>
						</el-form-item>
					</el-col>
				</el-row>
			</el-form>
      <template #footer>
				<span class="dialog-footer">
					<el-button @click="onCancel" size="default">取 消</el-button>
					<el-button type="primary" @click="onSubmit" size="default">新 增</el-button>
				</span>
			</template>
			</el-dialog>
    </div>
</template>

<script>
import doct from '@/api/doct';
export default {
    name: "doctList",
    methods:{
      //分页
        handleSizeChange(value) {
          this.pagination.size = value
          this.list(this.pagination.current,this.pagination.size);
       },
        handleCurrentChange(value) {
          this.pagination.current = value
          this.list(this.pagination.current,this.pagination.size);
       },
       del(pat){
         this.$confirm('此操作将永久删除名字为'+pat.daId+'的用户, 是否继续?', '提示', {
                    type: 'warning'
                    }).then(() => {
                        doct.deleteDoct(pat.daId).then(resp=>{
                             this.$message({type: 'success',message: resp.message});
                           this.list();
                        })
                    }).catch(() => {
                       this.$message({type: 'info',message: '已取消删除'});          
                    });
       } ,
      // 打开新增用户弹窗
		onOpenAddPati() {
             doct.getListDto().then(resp=>{
                this.patientsData=resp.patientsList;
                this.drugData=resp.drugList;
             })
            this.addTag=true;
        },
     // 关闭新增用户弹窗
    onCancel () {
         this.addTag = false;
         this.addDoctForm={};
         this.drugvalue=[];
    },
    
      list(pageym=1,pagesize=8){
            doct.findDoct1(pageym,pagesize,this.nameandid).then(resp=>{
               this.pagination=resp;
               console.log(this.pagination)
            });
        },
      //添加提交
    	onSubmit() {
        this.addDoctForm.wid=this.$store.state.userInfos.userInfos.user.userId
        console.log(this.drugvalue);
       doct.addDoct(this.addDoctForm,this.drugvalue).then(resp=>{
        this.$message({type: 'success',message: resp.message});
            		this.addTag=false;
                    this.addDoctForm={};
                    this.drugvalue=[];
            		this.list();
       })
    },
     
		
    },
        data() {
      return {
        pagination:{},//分页对象
        nameandid:"",//查询参数
        addTag:false,//是否显示添加弹窗
        addDoctForm:{},//添加医嘱
        drugData:{},//药品列表
        patientsData:{},//患者列表
        drugvalue: [],
        listli: [
					// 子集字段 + 属性值
					{
						id: Math.random(),
						label: '',
						value: '',
					},
        ],
        describe: '', // 字典描述
				fieldNameList: [], // 字段名: [{子集字段 + 属性值}]
      }
        }
    ,  
    mounted() {
        this.list(1,8);
    },
}
</script>

<style  scoped>
</style>
